

var log_store;
var log_proxy_config;
var log_proxy;
var log_reader;
var log_system_reader;		// system log reader
var log_store_config;
var log_columns;
var log_columns_system;		// system log
var pagingtoolbar_obj;

var gauge_cpu_obj;		// cpu usage gauge chart
var gauge_mem_obj;		// mem usage gauge chart
var gauge_sys_obj;		// system traffic throughput gauge chart

log_columns_system = new Array();
log_columns_system.push(grid_column_config_create('日期', 150, 'date', true, ''));
log_columns_system.push(grid_column_config_create('主机名称', 150, 'hostname', true, ''));
log_columns_system.push(grid_column_config_create('服务名称', 150, 'service', true, ''));
var config_syslog_column = grid_column_config_create('详情', 400, 'detail', true, '');
config_syslog_column.id  = 'log_system_expand_id';
log_columns_system.push(config_syslog_column);

log_reader = new Ext.data.JsonReader(
	{root: 'Data', totalProperty: 'TotalRecord'}, 	// root, totalProperty
	[
		{name: 'date',	mapping: 'date'},
		{name: 'username', mapping: 'username'},
		{name: 'type',	mapping: 'type'},
		{name: 'critical', mapping: 'critical'},
		{name: 'event', mapping: 'event'},
		{name: 'source', mapping: 'source'},
		{name: 'detail', mapping: 'detail'}
	]
);

log_system_reader = new Ext.data.JsonReader(
	{root: 'Data', totalProperty: 'TotalRecord'},
	[
		{name: 'date', mapping: 'date'},
		{name: 'hostname', mapping: 'hostname'},
		{name: 'service', mapping: 'service'},
		{name: 'detail', mapping: 'detail'}
	]
);


function log_audit_display()
{
	var search_url = 'bin/function_ajax.php?action=log_display';

	log_proxy_config = HttpProxy_config_create(search_url);
	log_proxy = new Ext.data.HttpProxy(log_proxy_config);
	log_store_config = Store_config_create(log_proxy, log_reader);
	log_store = new Ext.data.Store(log_store_config);
	log_store.load({ params: { start: 0, limit: 10} }); 
	//pagingtoolbar_obj.bindStore(log_store);

	var log_grid_comp = Ext.getCmp('log_display_grid_id1');
	log_grid_comp.autoExpandColumn = 'log_audit_expand_id';
	log_grid_comp.autoExpandMax = 2000;
	log_grid_comp.reconfigure(log_store, new Ext.grid.ColumnModel(log_columns));
}

function log_system_display()
{
	var search_url = 'bin/function_ajax.php?action=log_display_system';

	log_proxy_config = HttpProxy_config_create(search_url);
	log_proxy = new Ext.data.HttpProxy(log_proxy_config);
	log_store_config = Store_config_create(log_proxy, log_system_reader);
	log_store = new Ext.data.Store(log_store_config);
	log_store.load({ params: { start: 0, limit: 10} }); 
	//pagingtoolbar_obj.bindStore(log_store);

	var log_grid_comp = Ext.getCmp('log_display_grid_id1');
	log_grid_comp.autoExpandColumn = 'log_system_expand_id';
	log_grid_comp.autoExpandMax = 2000;
	log_grid_comp.reconfigure(log_store, new Ext.grid.ColumnModel(log_columns_system));
}

function log_filter_handler()
{
	var log_comp_yesno = Ext.getCmp('cond_yesno_id');
	var log_comp_type = Ext.getCmp('cond_type_id');
	var log_comp_match_value = Ext.getCmp('match_value_id0');
	var log_comp_date_start = Ext.getCmp('date_start_id');
	var log_comp_date_end = Ext.getCmp('date_end_id');

	var yesno = log_comp_yesno.value;
	var type  = log_comp_type.value;
	var match_value = log_comp_match_value.getValue();
	var date_start = log_comp_date_start.value;
	var date_end   = log_comp_date_end.value;

	var search_url = 'bin/function_ajax.php?action=log_display';
	search_url = search_url + '&' + 'yesno=' + yesno;
	search_url = search_url + '&' + 'type=' + type;
	search_url = search_url + '&' + 'match_value=' + match_value;
	search_url = search_url + '&' + 'date_start=' + date_start;
	search_url = search_url + '&' + 'date_end=' + date_end;

	// recreate data store
	log_proxy_config = HttpProxy_config_create(search_url);
	log_proxy = new Ext.data.HttpProxy(log_proxy_config);
	log_store_config = Store_config_create(log_proxy, log_reader);
	log_store = new Ext.data.Store(log_store_config);
	log_store.load({ params: { start: 0, limit: 10} }); 
//	pagingtoolbar_obj.bindStore(log_store);

	if (log_comp_type.value == 'date') {
		if (log_comp_date_start.value == '' || log_comp_date_end.value == '') {
			var config = messagebox_config_create('警告', '日期不能为空！', 
							true, 300, 300, Ext.Msg.OK, Ext.Msg.WARNING);
			Ext.MessageBox.show(config);
			return;
		}

		var log_grid_comp = Ext.getCmp('log_display_grid_id1');
		log_grid_comp.reconfigure(log_store, new Ext.grid.ColumnModel(log_columns));
		return;
	} else if (log_comp_type.value == 'nothing') {
		var log_grid_comp = Ext.getCmp('log_display_grid_id1');
		log_grid_comp.reconfigure(log_store, new Ext.grid.ColumnModel(log_columns));
		return;
	} else {
		if (log_comp_match_value.getValue() == '') {
			var config = messagebox_config_create('警告', '匹配条件不能为空！', 
							true, 300, 300, Ext.Msg.OK, Ext.Msg.WARNING);
			Ext.MessageBox.show(config);
			return;
		}
		var log_grid_comp = Ext.getCmp('log_display_grid_id1');
		log_grid_comp.reconfigure(log_store, new Ext.grid.ColumnModel(log_columns));
		return;
	}
}

function condition_change(combo, record, index)
{
	if (combo.value == 'nothing') {
		Ext.getCmp('match_id0').show();
		Ext.getCmp('match_value_id0').show();
		Ext.getCmp('match_value_id0').disable();
		Ext.getCmp('date_start_label_id').hide();
		Ext.getCmp('date_start_id').hide();
		Ext.getCmp('date_end_label_id').hide();
		Ext.getCmp('date_end_id').hide();
	} else if (combo.value == 'date') {
		Ext.getCmp('match_id0').hide();
		Ext.getCmp('match_value_id0').hide();
		Ext.getCmp('date_start_label_id').show();
		Ext.getCmp('date_start_id').show();
		Ext.getCmp('date_end_label_id').show();
		Ext.getCmp('date_end_id').show();
	} else {
		Ext.getCmp('match_id0').show();
		Ext.getCmp('match_value_id0').show();
		Ext.getCmp('match_value_id0').enable();
		Ext.getCmp('date_start_label_id').hide();
		Ext.getCmp('date_start_id').hide();
		Ext.getCmp('date_end_label_id').hide();
		Ext.getCmp('date_end_id').hide();
	}
}

function draw_cpu_graph(response, options)
{
	var json_obj = Ext.util.JSON.decode(response.responseText);
	var center_panel_obj = Ext.getCmp('centerPanel');

	var panel_config = panel_config_create('dashboard', '', false, '', '100%', '', '');
	panel_config.frame = false;

	var panel_cpu_config = panel_config_create('panel_dashboard_cpu_id1', 'CPU使用率', true, '', '100%', '', '');
	panel_cpu_config.frame = false;
	panel_cpu_config.layout = new Object();
	panel_cpu_config.layout.type = 'table';		// layout table
	panel_cpu_config.layout.columns = 2;
	panel_cpu_config.defaults = new Object();
	panel_cpu_config.defaults.frame = false;
	panel_cpu_config.bodyStyle	= 'background:#F1F1F1;';

/*
	var html = '<p style="color:green;background-color:#F1F1F1;"><b>使用的CPU ' + ' 单位（％）</b></p>';
	var config = component_config_create(html);
	config.colspan = 2;				// span column 2
	panel_cpu_config.items.push(config);
*/	
	var config = component_config_create('<canvas id="gauge_cpu_id1" width=200 height=200 style="background-color:#F1F1F1;"></canvas>');
	panel_cpu_config.items.push(config);


	var width = document.body.clientWidth - 200 - 400 - 70;
	var config_string = '<div id="cpu_id_id" style="background-color:black;height:200px;width:' + width + 'px;margin-left:auto;margin-right:auto;"></div>';
	var config = component_config_create(config_string);
	config.style = 'margin-left: 130px; margin-top:10px; margin-bottom:15px';
	panel_cpu_config.items.push(config);

	panel_config.items.push(panel_cpu_config);

	// memory usage panel
	var panel_memory_config = panel_config_create('panel_dashboard_memory_id1', 
						'内存使用率', true, '', '100%', '', '');
	panel_memory_config.frame = false;
	panel_memory_config.layout = new Object();
	panel_memory_config.layout.type = 'table';
	panel_memory_config.layout.columns = 2;
	panel_memory_config.defaults = new Object();
	panel_memory_config.defaults.frame = false;
	panel_memory_config.bodyStyle	= 'background:#F1F1F1;';
/*	
	var html = '<p style="color:green;background-color:#F1F1F1;"><b>使用的物理内存 ' + ' 单位（％）</b></p>';
	var config = component_config_create(html);
	config.colspan = 2;
	panel_memory_config.items.push(config);
*/	
	// memory gauge chart
	var config = component_config_create('<canvas id="gauge_memory_id1" width=200 height=200 style="background-color:#F1F1F1;"></canvas>');
	panel_memory_config.items.push(config);



	// memory line chart

	var config_string = '<div id="mem_id0" style="background-color:black;height:200px;width:' + width + 'px;margin-left:auto;margin-right:auto;"></div>';
	var config = component_config_create(config_string);
	config.style = 'margin-left: 130px; margin-top: 10px; margin-bottom: 15px;';
	panel_memory_config.items.push(config);

	panel_config.items.push(panel_memory_config);

	//仪表盘日志panel
	var panel_log_config = panel_config_create('panel_dashboard_log_id1', '日志', true, 320, '100%', '', '');
	panel_log_config.frame = false;
	panel_config.items.push(panel_log_config);
	panel_log_config.bodyStyle	= 'background:#F1F1F1;';

	// log display panel
	log_proxy_config = HttpProxy_config_create('bin/function_ajax.php?action=log_display');
	log_proxy = new Ext.data.HttpProxy(log_proxy_config);

	// create log store config
	log_store_config = Store_config_create(log_proxy, log_reader);

	// create log store
	log_store = new Ext.data.Store(log_store_config);

	// load data store
	log_store.load({ params: { start: 0, limit: 10} }); 

	var grid_config = grid_config_create('log_display_grid_id1', '', '100%', 330, 
						true, true, false, '', 
						log_store, new Ext.grid.CheckboxSelectionModel());
	grid_config.viewConfig 	= new Object();
//	grid_config.viewConfig.forceFit = true;
	grid_config.viewConfig.scrollOffset	= 0;

	grid_config.stripeRows 		= true,
	grid_config.autoExpandColumn 	= 'log_audit_expand_id';
	grid_config.autoExpandMax	= 2000;

	log_columns = new Array();
	log_columns.push(grid_column_config_create('日期', 150, 'date', true, ''));
	log_columns.push(grid_column_config_create('用户名称', 150, 'username', true, ''));
	log_columns.push(grid_column_config_create('类型', 150, 'type', true, ''));
	log_columns.push(grid_column_config_create('严重等级', 150, 'critical', true, ''));
	log_columns.push(grid_column_config_create('事件', 150, 'event', true, ''));
//	log_columns.push(grid_column_config_create('来源', 150, 'source', true, ''));
	var config_column = grid_column_config_create('来源', 150, 'source', true, '');
	config_column.hidden = true;
	log_columns.push(config_column);

	var config_column = grid_column_config_create('详情', 350, 'detail', true, '');
	config_column.id = 'log_audit_expand_id';
	log_columns.push(config_column);

	// add grid column
	grid_config.columns.push(log_columns[0], 
				log_columns[1], 
				log_columns[2],
				log_columns[3], 
				log_columns[4], 
				log_columns[5], 
				log_columns[6]);
	
	// add top bar
	var button_config = button_config_create('button', '审计日志', '', log_audit_display);
	grid_config.tbar.push(button_config);

	var button_config = button_config_create('tbseparator', '', '', '');
	grid_config.tbar.push(button_config);

	var button_config = button_config_create('button', '系统日志', '', log_system_display);
	grid_config.tbar.push(button_config);

/*
	pagingtoolbar_obj = pagingtoolbar_obj_create(10, log_store, true, 
							'显示第{0}条到{1}条记录，总共{2}条',
							'没有记录');
	grid_config.bbar.push(pagingtoolbar_obj);
*/

/*
	// add log search field
	panel_log_config.items.push(panel_log_search_config);
*/

	var grid_obj = new Ext.grid.GridPanel(grid_config);
	panel_log_config.items.push(grid_obj);

	// system traffic throughput
	var panel_system_config = panel_config_create('panel_dashboard_system_throughput_id1', 
							'系统流量吞吐', true, 300, '100%', '', '');
	panel_system_config.frame = false;
	panel_system_config.layout = "anchor";
	panel_system_config.bodyStyle	= 'background:#F1F1F1;';
	
	var config = component_config_create('<div id="linechart_system_id0" \
						style="width:100%;height:100%;background-color:black"></div>');
	config.anchor	= "60% 90%";
	config.border	= false;
	config.style	= "margin-left:auto; margin-right:auto; margin-top:10px;";
	panel_system_config.items.push(config);

	// add system traffic throughput panel to main panel
	panel_config.items.push(panel_system_config);

	// TCP concurrent, new incoming 
	var panel_tcp_config = panel_config_create('panel_dashboard_tcp_id1', 
						'TCP并发/新建连接', true, 300, '100%', '', '');
	panel_tcp_config.frame = false;
	panel_tcp_config.layout	= "anchor";
	panel_tcp_config.bodyStyle	= 'background:#F1F1F1;';

	// tcp concurrent,new incoming linechart
	var width = document.body.clientWidth - 420;
	var config = component_config_create('<div id="linechart_tcp_id0" \
						style="width:100%;height:100%;background-color:black;"></div>');
	config.anchor	= "60% 90%";
	config.border	= false;
	config.border	= false;
	config.style	= "margin-left:auto; margin-right:auto; margin-top:10px;";
	panel_tcp_config.items.push(config);

	// add tcp concurrent,new incoming panel to main panel
	panel_config.items.push(panel_tcp_config);

	// SSL traffic throughput
	var panel_ssl_throughput_config = panel_config_create('panel_dashboard_ssl_throughput_id1', 
								'SSL流量吞吐', true, 300, '100%', '', '');
	panel_ssl_throughput_config.frame = false;
	panel_ssl_throughput_config.layout = 'anchor';
	panel_ssl_throughput_config.bodyStyle	= 'background:#F1F1F1;';
	
	// SSL traffic throughput linechart
	var config = component_config_create('<div id="ssl_throughput_id0" \
						style="width:100%;height:100%;background-color:black;"></div>');
	config.anchor	= "60% 90%";
	config.border	= false;
	config.style	= "margin-left:auto; margin-right:auto; margin-top:10px;";
	panel_ssl_throughput_config.items.push(config);
	panel_config.items.push(panel_ssl_throughput_config);


	var panel_ssl_concurrent_config = panel_config_create('panel_dashboard_ssl_concurrent_id1', 
						'SSL并发/新建连接', true, 300, '100%', '', '');
	panel_ssl_concurrent_config.frame = false;
	panel_ssl_concurrent_config.layout = 'anchor';
	panel_ssl_concurrent_config.bodyStyle	= 'background:#F1F1F1;';

	// SSL concurrent, incoming linechart
	var config = component_config_create('<div id="linechart_ssl_concurrent_id0" \
						style="width:100%;height:100%;background-color:black;"></div>');
	config.anchor	= "60% 90%";
	config.border	= false;
	config.style	= "margin-left:auto; margin-right:auto; margin-top:10px;";
	panel_ssl_concurrent_config.items.push(config);
	// add tcp concurrent,new incoming panel to main panel
	panel_config.items.push(panel_ssl_concurrent_config);


	// HTTP transaction 
	var panel_http_transaction_config = panel_config_create('panel_dashboard_http_transaction_id1', 
						'HTTP事务处理', true, 300, '100%', '', '');
	panel_http_transaction_config.frame = false;
	panel_http_transaction_config.layout = 'anchor';
	panel_http_transaction_config.bodyStyle	= 'background:#F1F1F1';
	
	// HTTP transaction linechart
	var config = component_config_create('<div id="http_transaction_id0" \
						style="width:100%;height:100%;background-color:black;"></div>');
	config.anchor	= "60% 90%";
	config.border	= false;
	config.style	= "margin-left:auto; margin-right:auto; margin-top:10px;";
	panel_http_transaction_config.items.push(config);

	// add http transaction panel to main panel
	panel_config.items.push(panel_http_transaction_config);


	center_panel_obj.add(panel_config);
//	center_panel_obj.setActiveTab("dashboard");
	center_panel_obj.doLayout();
	Ext.getCmp('viewport_id1').doLayout();

	// very very important
	if ($.browser.msie) {
		var canvas_cpu = document.getElementById('gauge_cpu_id1');
		window.G_vmlCanvasManager.initElement(canvas_cpu);

		var canvas_mem = document.getElementById('gauge_memory_id1');
		window.G_vmlCanvasManager.initElement(canvas_mem);
	}

	// cpu gauge chart
 	var config = gauge_config_create('CPU Usage', '%', 0, 100, 5, 4, 0, 80, 80, 90, 90, 100, 3);
 	gauge_cpu_obj = new Gauge(document.getElementById('gauge_cpu_id1'), config);

	// memory gauge chart
	var config = gauge_config_create('MEM Usage', '%', 0, 100, 5, 4, 0, 80, 80, 90, 90, 100, 18);
	gauge_mem_obj = new Gauge(document.getElementById('gauge_memory_id1'), config);

	var cpu0_data = "Date,CPU使用率\n";	// cpu usage data
	var cpu0_seconds = 0;			// cpu usage time
	var mem0_data = "Date,内存使用率\n";	// memory usage data
	var mem0_seconds = 0;			// memory usage time

	for (var i = 0; i < 2; i++) {
		cpu0_data += cpu0_seconds + "," + 3 + "\n";
		mem0_data += mem0_seconds + "," + json_obj.mem_percent + "\n";
		cpu0_seconds++;
		mem0_seconds++;
	}

	// linechart color
	var colorSets = [ '#8AE234', '#FFA200' ];
	
	// CPU/MEM usage linechart config
	var linechart_config = linechart_config_create(colorSets, '#8AE234', true, [0, 100], true, '', '');

	// CPU usage linechart
//	linechart_config.yAxisLabelWidth = 20;
	linechart_config.legend 				= 'always';
	linechart_config.labelsDivStyles			= new Object();
	linechart_config.labelsDivStyles.textAlign 		= 'right';
	linechart_config.ylabel = '<p style="color:green;"><b>CPU使用率&nbsp;单位（%）</b></p>';

	var cpu0_linechart_comp = 
		new Dygraph(document.getElementById('cpu_id_id'), cpu0_data, linechart_config);

	// MEM usage linechart
	linechart_config.ylabel = '<p style="color:green;"><b>内存使用率&nbsp;单位（%）</b></p>';
	var mem0_linechart_comp = new Dygraph(document.getElementById('mem_id0'), mem0_data, linechart_config);

	var sys0_data = "Date,客户端吞吐,服务器端吞吐\n";	// system traffic throughput data
	var sys0_seconds = 0;					// system traffic throughput time
	//  system traffic throughput linechart
	var system_linechart_config = linechart_config_create(colorSets, '#8AE234', true, [0, 9999], false, '', '');
	
	system_linechart_config.legend 				= 'always';
	system_linechart_config.labelsDivStyles			= new Object();
	system_linechart_config.labelsDivStyles.textAlign 	= 'right';
	system_linechart_config.ylabel	= '<p style="color:green;"><b>系统流量吞吐&nbsp;单位（MB）</b></p>';
	// draw system throughput linechart
	var sys0_linechart_comp = new Dygraph(document.getElementById('linechart_system_id0'), 
						sys0_data, 
						system_linechart_config);

	var tcp0_data = "Date,TCP并发连接,TCP新建连接\n";
	var tcp0_seconds = 0;
	//  tcp concurrent,incoming linechart
	var tcp_linechart_config = linechart_config_create(colorSets, '#8AE234', 
								true, [0, 1000], 
								false, '', '');
	tcp_linechart_config.legend 				= 'always';
	tcp_linechart_config.labelsDivStyles			= new Object();
	tcp_linechart_config.labelsDivStyles.textAlign 		= 'right';
	tcp_linechart_config.ylabel = '<p style="color:green;"><b>TCP并发/新建连接&nbsp;单位（K）</b></p>';
	// draw tcp concurrent,new incoming linechart
	var tcp0_linechart_comp = new Dygraph(document.getElementById('linechart_tcp_id0'), 
						tcp0_data, 
						tcp_linechart_config);

	var ssl0_throughput_data = "Date,SSL客户端吞吐,SSL服务器端吞吐\n";	// SSL traffic throughput data
	var ssl0_throughput_seconds = 0;				// SSL traffic throughput time
	// SSL traffic throughput linechart
	var ssl_throughput_linechart_config = linechart_config_create(colorSets, '#8AE234', 
									true, [0, 9999], 
									false, '', '');
	ssl_throughput_linechart_config.legend 				= 'always';
	ssl_throughput_linechart_config.labelsDivStyles			= new Object();
	ssl_throughput_linechart_config.labelsDivStyles.textAlign 	= 'right';
	ssl_throughput_linechart_config.ylabel = '<p style="color:green;"><b>SSL流量吞吐&nbsp;单位（MB）</b></p>';
	// draw SSL traffic throughput linechart
	var ssl_througput_linechart_comp = new Dygraph(document.getElementById('ssl_throughput_id0'), 
						ssl0_throughput_data, 
						ssl_throughput_linechart_config);

	// SSL concurrent, incoming
	var ssl0_concurrent_data = "Date,SSL并发连接,SSL新建连接\n";
	var ssl0_concurrent_seconds = 0;
	// SSL concurrent,incoming linechart
	var ssl0_concurrent_linechart_config = 
				linechart_config_create(colorSets, '#8AE234', 
							true, [0, 1000], 
							false, '', '');
	ssl0_concurrent_linechart_config.legend 				= 'always';
	ssl0_concurrent_linechart_config.labelsDivStyles			= new Object();
	ssl0_concurrent_linechart_config.labelsDivStyles.textAlign 		= 'right';
	ssl0_concurrent_linechart_config.ylabel = '<p style="color:green;"><b>SSL并发/新建连接&nbsp;单位（K）</b></p>';
	// draw tcp concurrent,new incoming linechart
	var ssl0_concurrent_linechart_comp = new Dygraph(document.getElementById('linechart_ssl_concurrent_id0'), 
						ssl0_concurrent_data, 
						ssl0_concurrent_linechart_config);


	/*******************************************************************/
	// http transaction
	var http_transaction_data = "Date,HTTP请求速率\n";
	var http_transaction_seconds = 0;
	// SSL concurrent,incoming linechart
	var http_transaction_linechart_config = linechart_config_create(colorSets, '#8AE234', 
									true, [0, 1000], 
									false, '', '');
	http_transaction_linechart_config.legend 				= 'always';
	http_transaction_linechart_config.labelsDivStyles			= new Object();
	http_transaction_linechart_config.labelsDivStyles.textAlign 		= 'right';
	http_transaction_linechart_config.ylabel = '<p style="color:green;"><b>HTTP事务处理&nbsp;单位（K）</b></p>';
	// draw tcp concurrent,new incoming linechart
	var http_transaction_linechart_comp = new Dygraph(document.getElementById('http_transaction_id0'), 
						http_transaction_data, 
						http_transaction_linechart_config);

	/*******************************************************************/

	// cpu0 "0,12\n1,22\n2,10\n"
	function cpu0_set(value)	// cpu linechart change
	{	
		cpu0_data += cpu0_seconds + "," + value + "\n";
		cpu0_seconds++;
		cpu0_linechart_comp.updateOptions({'file': cpu0_data});
		var res_array = cpu0_data.split("\n");
		if (res_array.length >= 100) {
			cpu0_data = "Date,CPU使用率\n";
			for (i = 10; i < 100; i++) {
				cpu0_data += res_array[i];
				cpu0_data += "\n";
			}
		}
	}

	function mem0_set(value)	// memory linechart change
	{
		mem0_data += mem0_seconds + "," + value + "\n";
		mem0_seconds++;
		mem0_linechart_comp.updateOptions({'file': mem0_data});
		var res_array = mem0_data.split("\n");
		if (res_array.length >= 100) {
			mem0_data = "Date,内存使用率\n";
			for (i = 10; i < 100; i++) {
				mem0_data += res_array[i];
				mem0_data += "\n";
			}
		}
	}

	// system throughput, tcp concurrent,new incoming linechart change
	function sys0_sysstats_set(json_obj)
	{
		// system throughput linechart change
		sys0_data += sys0_seconds + "," + json_obj.system_throughput_upTraffic 
				+ "," + json_obj.system_throughput_downTraffic + "\n";
		sys0_seconds++;
		sys0_linechart_comp.updateOptions({'file': sys0_data});
		var res_array = sys0_data.split("\n");
		if (res_array.length >= 100) {
			sys0_data = "Date,客户端吞吐,服务器端吞吐\n";
			for (i = 10; i < 100; i++) {
				sys0_data += res_array[i];
				sys0_data += "\n";
			}
		}

		// tcp concurrent, new incoming linechart change
		tcp0_data += tcp0_seconds + "," + json_obj.tcp_concurrent 
				+ "," + json_obj.tcp_incoming + "\n";
		tcp0_seconds++;
		tcp0_linechart_comp.updateOptions({'file': tcp0_data});
		var res_array = tcp0_data.split("\n");
		if (res_array.length >= 100) {
			tcp0_data = "Date,TCP并发连接,TCP新建连接\n";
			for (i = 10; i < 100; i++) {
				tcp0_data += res_array[i];
				tcp0_data += "\n";
			}
		}


		// SSL throughput linechart
		ssl0_throughput_data += ssl0_throughput_seconds + "," + json_obj.ssl_throughput_upTraffic
					+ "," + json_obj.ssl_throughput_downTraffic + "\n";
		ssl0_throughput_seconds++;
		ssl_througput_linechart_comp.updateOptions({'file': ssl0_throughput_data});
		var res_array = ssl0_throughput_data.split("\n");
		if (res_array.length >= 100) {
			tcp0_data = "Date,SSL客户端吞吐,SSL服务器端吞吐\n";
			for (i = 10; i < 100; i++) {
				ssl0_throughput_data += res_array[i];
				ssl0_throuhgput_data += "\n";
			}
		}

		// SSL concurrent, new incoming linechart
		ssl0_concurrent_data += ssl0_concurrent_seconds + "," + json_obj.ssl_concurrent
					+ "," + json_obj.ssl_incoming + "\n";
		ssl0_concurrent_seconds++;
		ssl0_concurrent_linechart_comp.updateOptions({'file': ssl0_concurrent_data});
		var res_array = ssl0_concurrent_data.split("\n");
		if (res_array.length >= 100) {
			ssl0_concurrent_data = "Date,SSL并发连接,SSL新建连接\n";
			for (i = 10; i < 100; i++) {
				ssl0_concurrent_data += res_array[i];
				ssl0_concurrent_data += "\n";
			}
		}

		// http transaction
		http_transaction_data += http_transaction_seconds + "," + json_obj.http_request_rate + "\n";
		http_transaction_seconds++;
		http_transaction_linechart_comp.updateOptions({'file': http_transaction_data});
		var res_array = http_transaction_data.split("\n");
		if (res_array.length >= 100) {
			http_transaction_data = "Date,HTTP请求速率\n";
			for (i = 10; i < 100; i++) {
				http_transaction_data += res_array[i];
				http_transaction_data += "\n";
			}
		}

	}

	// flush cpu,memory usage
	dashboard_cpu_memory_timer = setInterval(function() {
		function cpu_usage(response, options)
		{
			var json_obj = Ext.util.JSON.decode(response.responseText);

			var cpu_value = json_obj.cpu_total * 100 / 100;
//			gauge_cpu_obj.setValue(cpu_value);


			// redraw cpu gauge
 			var config = gauge_config_create('CPU Usage', '%', 0, 100, 5, 4, 
							0, 80, 80, 90, 90, 100, cpu_value);
 			gauge_cpu_obj = new Gauge(document.getElementById('gauge_cpu_id1'), config);


			var mem_value = json_obj.mem_percent * 100 / 100;
//			gauge_mem_obj.setValue(mem_value);

			// redraw memory gauge
 			var config = gauge_config_create('MEM Usage', '%', 0, 100, 5, 4, 
							0, 80, 80, 90, 90, 100, mem_value);
 			gauge_mem_obj = new Gauge(document.getElementById('gauge_memory_id1'), config);


			cpu0_set(Math.abs(cpu_value));
			mem0_set(Math.abs(mem_value));
		}

		var ajax_config = 
				ajax_config_create('bin/sysadmin_action.php?action=getinfo&operation=cpu_usage', 
						'POST', 
						cpu_usage);
		Ext.Ajax.request(ajax_config);
	}, 1000);

	dashboard_traffic_timer = setInterval(function(){
		function sys_throughput(response, options)
		{
			var json_obj = Ext.util.JSON.decode(response.responseText);
			sys0_sysstats_set(json_obj);
		}

		var ajax_config = 
			ajax_config_create('bin/sysadmin_action.php?action=getinfo&operation=sys_throughput', 
					'POST', 
					sys_throughput);
		Ext.Ajax.request(ajax_config);
	}, 5000);

	dashboard_already_clicked = false;	// unlock
}

function dashboard_handler()
{
	Ext.getCmp('action-panel').hide();
	Ext.getCmp('centerPanel').setWidth('100%');

	
	
	// document.body.clientWidth
	// document.body.clientHeight
	// document.documentElement.clientWidth
	// document.documentElement.clientHeight

	var center_panel_obj = Ext.getCmp('centerPanel');
	center_panel_obj.items.each(function(c) { center_panel_obj.remove(c); });
//	center_panel_obj.doLayout();
	//center_panel_obj.setActiveTab("dashboard");
	
	Ext.getCmp('viewport_id1').doLayout();

	var ajax_config = ajax_config_create('bin/sysadmin_action.php?action=getinfo&operation=cpu_number', 
						'POST', 
						draw_cpu_graph);
	Ext.Ajax.request(ajax_config);
}
